The documentation for systems that generate or translate programs often use exemplars to describe their output format. These exemplars should become part of the translator itself as formal 'templates' (output grammars) to describe the structure of output sentences.
While this talk will focus on code generation and source translation issues, my StringTemplate engine actually emerged while building the dynamic pages for large commercial websites. To my great surprise, the simple embedded language evolved to have a distinctly functional flavor! I will begin in that domain to motivate the key distinguishing feature of StringTemplate: enforced strict separation of logic from presentation. All benefits such as ease of development, flexibility, reduced maintenance costs, parallel code, HTML generation etc... derive from this single principle of separation.
There are a few interesting side effects and properties of restricted templates. In the web domain, enforced separation equals enforced security for look-n-feel templates exposed to end-users of hosted applications. In the language translation domain, enforced separation yields a guarantee that your system is retargetable because there can be no logic embedded in the target language specification and there are no print statements strewn throughout the logic code.
I will demonstrate my StringTemplate engine at work solving some nontrivial generation tasks and show how StringTemplate is used in the code generator for the upcoming ANTLR 3.0 parser generator.